package tools;

import javax.swing.JPanel;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

/**
 * Title:
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:
 * @author
 * @version 1.0
 */

public class AbstractProcess extends JPanel implements ProcessPanel {

  transient private Vector<ActionListener> actionListeners = new Vector<ActionListener>();

  public AbstractProcess() {
    setLayout( new BorderLayout() );
  }

  public Map getActions() {
    return null;
  }

  public void removeActionListener( ActionListener l ) {
    synchronized ( actionListeners ){
      if ( actionListeners.contains( l ) ) {
        actionListeners.removeElement( l );
      }
    }
  }

  public void addActionListener( ActionListener l ) {
    synchronized ( actionListeners ){
      if ( ! actionListeners.contains( l ) ) {
        actionListeners.addElement(l);
      }
    }
  }

  protected void fireActionPerformed( ActionEvent e ) {
    Vector listeners = null;

    synchronized ( actionListeners ){
      listeners = (Vector)actionListeners.clone();
    }

    int count = listeners != null ? listeners.size() : 0;
    for (int i = 0; i < count; i++) {
      ((ActionListener) listeners.elementAt(i)).actionPerformed(e);
    }
  }
}